package com.smartstate.IOC.controller;


import com.smartstate.IOC.entity.Alarm;
import com.smartstate.IOC.service.AlarmService;
import com.smartstate.IOC.vo.AlarmVo;
import com.smartstate.common.web.httpResult.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = {"设备警报汇总"})
@RequestMapping("/Alarm")
public class AlarmController {

    @Resource
    private AlarmService alarmService;

    /**
     * 查询最近三天的设备警报汇总
     *
     * @return
     */
    @GetMapping("/pageAlarm")
    @ApiOperation(value = "设备报警")
    public List<Alarm> pageAlarm() {
        return alarmService.getLastTime();
    }


    @GetMapping("/getAlarmCount")
    @ApiOperation(value = "运维态势-综合告警事件统计")
    public ResultVO<List<Map<String, Object>>> getAlarmCount() {
        List result = Lists.newArrayList();
        try {
            result.add(alarmService.getAlarmCountByType("").get());
            result.add(alarmService.getAlarmCountByType("1").get());
            result.add(alarmService.getAlarmCountByType("2").get());
            result.add(alarmService.getAlarmCountByType("3").get());
        } catch (Exception e) {
            return ResultVO.error("获取警报次数汇总出现错误！");
        }
        return ResultVO.success(result);
    }


    @GetMapping("/selectAlarmPage")
    @ApiOperation(value = "环境告警事件展示")
    public List<AlarmVo> selectAlarmPage() {
        return alarmService.queryPageList();
    }

    @GetMapping("/getEnvironAlarm")
    @ApiOperation(value = "综合态势-环境监控")
    public Map<String, Object> getEnvironAlarm() {
        return alarmService.getEnvironAlarm();
    }

    @GetMapping("/getAlarmTotal")
    @ApiOperation(value = "设备报警次数统计")
    public Map<String, Integer> getAlarmTotal() {
        return alarmService.getAlarmTotal();
    }

    @GetMapping("/getThreeAlarm")
    @ApiOperation(value = "环境告警趋势分析")
    public  Map<String, Long> getThreeAlarm() {
        return alarmService.getThreeAlarm();
    }

    @GetMapping("/getEnvironTotal")
    @ApiOperation(value = "环境告警事件统计")
    public  Map<String, Integer> getEnvironTotal() {
        return alarmService.getEnvironTotal();
    }

    @GetMapping("/getEquimentAlarm")
    @ApiOperation(value = "运维态势-报警统计")
    public Map<String, Object> getEquimentAlarm() {
        return alarmService.getEquimentAlarm();
    }


}
